--[[/**
每秒回血
-- */]]

---@class BuffEffect613101 : BaseBuffEffect
BuffEffect613101 = ClientFight.CreateClass("BuffEffect613101", ClientFight.BaseBuffEffect)
local t = BuffEffect613101

---@param fight Fight
---@param buff FighterBuff
function t:action(fight, buff, ...)
    local maxHp = FighterAttributeManager.getFightAttr(buff.target, FighterAttributeEnum.HP);
    local addHpHide = buff.target.parametersByObject[BuffEffect615102.BuffEffect615102_HIDE_HP] or 0;
    if (addHpHide > 0) then
        SkillRoleMgr.savePathFile("[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
                .. buff.modelId .. " 使用隐藏血量,在复活时,加上这个额外的回血量：" .. addHpHide);
        local remainHpHide = addHpHide - FighterAttributeManager.getFightAttr(buff.target, FighterAttributeEnum.HP);
        if (remainHpHide < 0) then
            remainHpHide = 0;
        end
        buff.target.parametersByObject[BuffEffect615102.BuffEffect615102_HIDE_HP] = remainHpHide;
    end
    local addHp = addHpHide + Utils.calcRatio(maxHp, buff.buffBean.f_BuffEffectValue[1]);
    if (addHp > maxHp) then
        addHp = maxHp;
    end
    -- 把血加回来
    DamageManager.setFighterHp(fight, buff.target, buff.target, nil, DamageResultTypeEnum.HEAL, addHp,
            buff.target.hp + addHp, false, false, false);
    local addBuff = nil;
    if (not buff.target:isSummons()) then
        local result = BuffManager.addBuff(fight, buff.skill, buff.target, buff.target.puppet, false, buff.buffBean.f_BuffEffectValue[2], 1);
        local o = result[1];
        if (o == IBuffEffect.SUCCESS_ATTRI_HAS_CHANGE) then
            addBuff = result[2];
        end
    end

    local logAddHp = addHp;
    SkillRoleMgr.savePathFile("[" .. fight.frame .. "][EFFECT]Fighter " .. buff.target.fighterId .. " Buff"
            .. buff.modelId .. " 触发回血：" .. logAddHp);
    if (buff.target.hp >= maxHp) then
        if (addBuff ~= nil) then
            BuffManager.removeFighterBuff(fight, buff.target.puppet, addBuff, true);
        end
        return IBuffEffect.REMOVE;--回满了血就移除
    end
    return ClientFight.BaseBuffEffect.action(self, fight, buff, ...);
end
function t:remove(fight, buff, force, ...)
    --		6111101
    local puppet = buff.target.puppet;
    if (puppet ~= nil and not buff.target:isSummons()) then
        BuffManager.removeFightBuff(fight, buff.target.puppet, buff.buffBean.f_BuffEffectValue[2], true);
        puppetSHowSkill(fight, puppet, 6111101);
    end
    return ClientFight.BaseBuffEffect.remove(self, fight, buff, force, ...);

end

function t:puppetSHowSkill(fight, puppet, skillId)
    local skill = SkillManager.createFightSkill(fight, skillId, puppet);
    local usingSkill = FightUsingSkill.New();
    usingSkill.skillUniqueId = fight.skillIds.andIncrement;
    usingSkill.fight = fight;
    usingSkill.fighter = puppet;
    usingSkill.target = puppet;
    usingSkill.skill = skill;
    usingSkill.parentSkill = usingSkill;
    usingSkill.speed = SkillManager.countSkillSpeed(usingSkill);
    local attack = ReportManager.attackToJsonString(fight, puppet, puppet, usingSkill, usingSkill.speed);
    table.insert(fight.actions, attack)
    FightManager.playActions(attack)
end
t.New()